﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using Function;
using System.Text;

namespace UI.Module.InvestmentIncome
{

    public partial class ShopEarnings : System.Web.UI.Page
    {

        public List<ShopEarning> list = null;
        protected string strMessege = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                list = new List<ShopEarning>();
                ST_InvestorBLL bll = new ST_InvestorBLL();
                //投资者下的门店列表信息
                string shopID = "";
                DataSet shoplist = new GX_InvestorShopBLL().GetList("InvestorID=" + Method.CurrentUserID);
                foreach (DataRow item1 in shoplist.Tables[0].Rows)
                {
                    shopID += item1["ShopID"] + ",";
                }
                if (shopID != "")
                {
                    //门店年销售任务
                    DataSet modelList = new ST_ShopSellMissionBLL().GetListByshiopID("Year=" + DateTime.Now.Year + " and ShopID in(" + ExtensionMethod.subLastChar(shopID) + ")");
                    if (modelList.Tables[0].Rows.Count > 0)
                    {
                        foreach (DataRow item in modelList.Tables[0].Rows)
                        {
                            ShopEarning model = new ShopEarning();
                            //年销量与收益
                            DataTable nds = bll.Get_nyr(1, item["ShopID"].ToInt32(), out strMessege);
                            //月销量与收益
                            DataTable yds = bll.Get_nyr(2, item["ShopID"].ToInt32(), out strMessege);
                            //日销量与收益
                            DataTable rds = bll.Get_nyr(3, item["ShopID"].ToInt32(), out strMessege);

                            model.Id = item["ShopID"].ToInt32();
                            model.ShopName = item["ShopName"].ToString();
                            model.Nrw = String.Format("{0:F}", item["SellMission"]);
                            model.Nsj_rw = String.Format("{0:F}", item["PledgeGain"]);
                            model.Nsy = nds.Rows.Count > 0 ? String.Format("{0:F}",nds.Rows[0]["InCome"]) : "0.00";
                            model.Ysy = yds.Rows.Count > 0 ? String.Format("{0:F}",yds.Rows[0]["InCome"]) : "0.00";
                            model.Rsy = rds.Rows.Count > 0 ? String.Format("{0:F}",rds.Rows[0]["InCome"]) : "0.00";

                            model.Nje = nds.Rows.Count > 0 ? String.Format("{0:F}",nds.Rows[0]["AllOrderMoney"]) : "0.00";
                            model.Yje = yds.Rows.Count > 0 ? String.Format("{0:F}",yds.Rows[0]["AllOrderMoney"]): "0.00";
                            model.Rje = rds.Rows.Count > 0 ? String.Format("{0:F}",rds.Rows[0]["AllOrderMoney"]) : "0.00";
                            list.Add(model);
                        }

                    }
                }
                else {
                    MessageBox_Page McBx = new MessageBox_Page();//实例化对话框
                    string RemarkString;
                    RemarkString = "暂无门店信息";

                    McBx.Title = "系统提示";
                    McBx.AddContent(RemarkString);
                    McBx.Type = MsgType.Error;
                    McBx.AddUrl("返回", "../../Module/User/UserMsge.aspx", UrlType.Href);
                    MessageEvent.MessageBox(McBx, "../../ErrorPage/ShowMsg.aspx");
                    return;
                }
            }
        }
    }
}